<template>
  <div class="ele-body">
   
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <log-search @search="reload" />
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        :selection.sync="selection"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
         
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            class="ele-btn-icon"
            @click="removeBatch"
          >
            删除
          </el-button>
          
        </template>

      


        <template v-slot:account="{ row }">
          <div class="ele-cell-content">
            <div class="ele-cell-title">{{ row.figureAccount.telphone }} </div>
          </div>
          
        </template>


     


        <template v-slot:type="{ row }">
          <div v-if="row.type==1">
            <div>
              <span class="package-name"> {{row.name}}</span>
              <span class="package-money"> ¥{{row.money}}</span>
              <el-tag type="warning" effect="light" size="small" v-if="row.type==1">{{row.day}} 天</el-tag>
            </div>
            
            <div> 形象克隆 {{row.is_infinite == 1 ? '无限' : row.avatar_twin_count}} （次）</div>
            <div> 声音克隆 {{row.is_infinite == 1 ? '无限' : row.voice_twin_count}} （次）</div>
            <div> 视频剪辑 {{row.is_infinite == 1 ? '无限' : row.video_clip_count}} （秒）</div>
          </div>
          <div v-else>
            <div>
              <span class="package-name"> {{row.name}}</span>
              <span class="package-money"> ¥{{row.money}}</span>
            </div>
            <div>{{row.point}} （点）</div>
          </div>
        </template>




        <template v-slot:info="{ row }">
          <div class="ele-cell-content">
            <div class="ele-cell-title">{{ row.name }} </div>
          </div>
          
        </template>

       
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
         
          <el-popconfirm
            class="ele-action"
            title="确定要删除此数据吗？"
            @confirm="remove(row)"
          >
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
   
  </div>
</template>

<script>
  import VueCountUp from 'vue-countup-v2';
  import LogSearch from './components/log-search';
  import { list, remove, modify,statis } from '@/api/package/log';

  export default {
    name: 'AccountLog',
    components: {
      LogSearch,
      VueCountUp
    },
    data() {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'selection',
            type: 'selection',
            width: 45,
            align: 'center',
            fixed: 'left'
          },
         
          {
            prop: 'account',
            label: '账号',
            showOverflowTooltip: true,
            minWidth: 110,
            slot: 'account'
          },
          {
            prop: 'info',
            label: '套餐信息',
            showOverflowTooltip: true,
            minWidth: 110,
            slot: 'info'
          },
          {
            prop: 'type',
            label: '套餐类型',
            showOverflowTooltip: true,
            minWidth: 110,
            slot: 'type'
          },
          {
            prop: 'money',
            label: '套餐价格',
            showOverflowTooltip: true,
            minWidth: 110,
          },
          {
            prop: 'create_time',
            label: '操作时间',
            showOverflowTooltip: true,
            minWidth: 100
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 350,
            align: 'center',
            resizable: false,
            slot: 'action',
            hideInSetting: true,
            showOverflowTooltip: true
          }
        ],
        // 表格选中数据
        selection: [],
        // 当前编辑数据
        current: null,
        // 是否显示编辑弹窗
        showEdit: false,
        // 是否显示分配回收员
        showCollector: false,
        //弹框名称
        id:0,
        all:0,
        get:0,
        out:0,
      };
    },
    methods: {
      beforeHandleCommand(index, row,command){
        return {
          'index': index,
          'row': row,
          'command':command
        }
      },
      /* 下拉菜单点击事件 */
      onDropClick(command) {
        if (command.command === 'password') {
          this.openReserve(command.row);
        } else if (command.command === 'appsecret') {
          this.openPack(command.row);
        } 
      },
     
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return list({ ...where, ...order, page, limit });
      },
      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ page: 1, where: where });
      },
      /* 打开编辑弹窗 */
      openEdit(row) {
        this.current = row;
        this.showEdit = true;
      },
      /* 删除 */
      remove(row) {
        const loading = this.$loading({ lock: true });
        remove(row.id).then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
      },

    
      
      /* 批量删除 */
      removeBatch() {
        if (!this.selection.length) {
          this.$message.error('请至少选择一条数据');
          return;
        }
        this.$confirm('确定要删除选中的数据吗?', '提示', {
          type: 'warning'
        }).then(() => {
          const loading = this.$loading({ lock: true });
          remove(this.selection.map((d) => d.id))
            .then((msg) => {
              loading.close();
              this.$message.success(msg);
              this.reload();
            })
            .catch((e) => {
              loading.close();
              this.$message.error(e.message);
            });
        }).catch(() => {});
      },
      dataStatis(){
        statis().then((data) => {
          if(data != null){
            this.all = data.all;  
            this.get = data.get;  
            this.out = data.out;  
          }
          
        }).catch((e) => {
          this.$message.error(e.message);
        });
      },
    
    }
  };
</script>

<style lang="scss" scoped>
 .package-name{
  color: #1367DE;
  font-size: 14px;
  margin-right: 5px;
 }
 .package-money{
  color:#FF0000;
  font-size: 18px;
  margin-right: 5px;
 }
 .drag {
    background: #000 !important;
    background-image: linear-gradient(#333, #999) !important;
  }

  .ele-cell-content {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .card_box_cir1 .iconfont {
      font-size: 26px;
      color: #fff;
  }

  .card_box {
      width: 100%;
      height: 100%;
      display: flex;
      -webkit-box-align: center;
      align-items: center;
      box-sizing: border-box;
      border-radius: 4px;
  }
  .card_box .card_box_cir .card_box_cir1, .card_box .card_box_cir {
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
  }



  .card_box .card_box_cir .card_box_cir1, .card_box .card_box_cir {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    -webkit-box-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    align-items: center;
  }

  
  .card_box .card_box_cir {
    width: 60px;
    height: 60px;
    overflow: hidden;
    margin-right: 20px;
  }

  .card_box .card_box_txt .sp1 {
    display: block;
    color: #252631;
    font-size: 24px;
  }

  .card_box .card_box_txt .sp2 {
    display: block;
    color: #98a9bc;
    font-size: 12px;
  }

  .one {
      background: #e4ecff;
  }

  .two {
    background: #fff3e0;
  }

  .three {
    background: #eaf9e1;
  }

  .one1 {
    background: #4d7cfe;
  }
  .two1 {
    background: #ffab2b;
  }
  .three1 {
    background: #6dd230;
  }
</style>
